<?php

namespace App\Http\Model;

use Illuminate\Support\Facades\DB;

class PropUserPackLog extends Base
{
    protected $table = 'prop_user_pack_log';

    public function __construct(array $attributes = [])
    {
        parent::__construct($this->table, $attributes);
    }

    /**
     * 用户背包使用记录-创建
     *
     * @param string $type 操作类型 默认 insert=创建，update=更新
     * @param int $userId 用户ID
     * @param int $propId 道具ID
     * @param int $propEventId 道具功能ID
     * @param int $data_value 生成具体数据值
     * @param int $prop_log_id 道具使用日志
     * @return bool
     * */
    public function updateOrInsertUserPackLog($userId, $propId, $propEventId, $data_value, $prop_log_id, $type = 'insert')
    {
        switch ($type) {
            case 'insert':
                $data = [
                    'user_id' => $userId,
                    'prop_id' => $propId,
                    'prop_event_id' => $propEventId,
                    'target_id' => 0,
                    'created_at' => time(),
                    'data_num' => $data_value,
                    'prop_log_id' => $prop_log_id
                ];
                $ret = DB::table($this->table)->insertGetId($data);
                break;
            default:
                $ret = false;
                break;
        }

        return $ret;
    }
}